草庐IT

android - 无法实例化 android.gms.maps.MapFragment

全部标签

ruby - 如何替换 ruby​​ 中模式的每个实例?

string.sub看起来它只替换了第一个实例。是否有可以替代所有模式的选项或其他方法?你能在perl之类的正则表达式中完成吗?(我觉得像r/blah/blah/)...并+1给任何能告诉我为什么string.sub只替换第一个匹配项的人? 最佳答案 String.gsub应该可以解决问题。引用文档:gsub(pattern,replacement)→new_strReturnsacopyofstrwiththealloccurrencesofpatternsubstitutedforthesecondargument.Thepat

ruby-on-rails - 升级到 Yosemite 10.10 后无法连接到 postgresql 数据库

更新到Yosemite10.10后,我无法连接到我的postgresql数据库。我运行Rails控制台并尝试获取第一个用户,但出现此错误...>➜game_golfgit:(master)✗railsc>Loadingdevelopmentenvironment(Rails4.1.4)>[1]pry(main)>User.first>PG::ConnectionBad:couldnotconnecttoserver:Connectionrefused>Istheserverrunningonhost"localhost"(::1)andaccepting>TCP/IPconnectio

ruby - 无法在 Eclipse 4.2 上安装 Aptana 插件

我已经安装了Eclipse4.2Juno。现在我想安装aptana来开发ruby,但是我得到以下错误,Unabletoreadrepositoryathttp://download.aptana.com/studio3/plugin/install/content.jar.无法读取位于http://download.aptana.com/studio3/plugin/install/content.jar的存储库.读取超时 最佳答案 我认为到目前为止您可能已经解决了问题,但我遇到了完全相同的问题并在多次搜索后找到了解决方案,所以为了

ruby-on-rails - 如何在 Ruby 中创建一个新的 Date 实例

如何在给定日期的IRB中创建一个新的日期对象。以下无效。1.9.3p194:053>require'active_support'=>true1.9.3p194:054>Date.new=>#1.9.3p194:055>Date.parse('12/01/2012')NoMethodError:undefinedmethod`parse'forDate:Classfrom(irb):551.9.3p194:055>Date.new('12/01/2012')ArgumentError:wrongnumberofarguments(1for0) 最佳答案

ruby-on-rails - 运行 heroku create --stack cedar 时无法加载此类文件 -- readline (LoadError)

我正在尝试将我的Rails应用程序部署到Heroku以按照以下说明进行测试:http://devcenter.heroku.com/articles/rails3#prerequisites这是我要运行的命令:herokucreate--stackcedar我收到此错误消息:/home/sergio/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in`require':cannotloadsuchfile--readline(LoadError)from/home/s

ruby - rspec:如何 stub 构造函数调用的实例方法?

classAdefinitialize@x=do_somethingenddefdo_something42endend如何在调用原始实现之前在rspec中stubdo_something(从而将42分配给@x)?当然,在不改变实现的情况下。 最佳答案 Here'sthecommitwhichaddsthefeaturetorspec-这是在2008年5月25日。有了这个你可以做A.any_instance.stub(do_something:23)但是,rspec的最新gem版本(1.1.11,2008年10月)没有这个补丁。Th

ruby - 无法在生产服务器上更新 gem

无法在生产服务器上更新gem。我已经尝试过bundleinstall--deployment和bundleinstall--withoutdevelopmenttest但不断得到:YouaretryingtoinstallindeploymentmodeafterchangingyourGemfile.Run`bundleinstall`elsewhereandaddtheupdatedGemfile.locktoversioncontrol.Ifthisisadevelopmentmachine,removetheGemfilefreezebyrunning`bundleinstal

ruby - 如何为动态实例变量设置 attr_accessor?

我在我的类中动态创建了一个实例变量:classMineattr_accessor:some_vardefintialize@some_var=trueenddefmy_numbernumself.instance_variable_set"@my_#{num}",numendend如何让@my_#{num}现在成为一个attr值?例如我希望能够做到这一点:dude=Mine.newdude.my_number1dude.my_1=>1 最佳答案 这个答案不会污染类空间,例如..如果我执行mine.my_number4那么Mine的其

ruby - 如何使对象实例成为 Ruby 中的哈希键?

我有一个带有几个成员变量的Foo类。当类的两个实例中的所有值都相等时,我希望对象“相等”。然后我希望这些对象成为我的散列中的键。当我目前尝试这样做时,哈希将每个实例视为不平等。h={}f1=Foo.new(a,b)f2=Foo.new(a,b)此时f1和f2应该相等。h[f1]=7h[f2]=8putsh[f1]应该打印8 最佳答案 参见http://ruby-doc.org/core/classes/Hash.htmlHashuseskey.eql?totestkeysforequality.Ifyouneedtouseinsta

ruby - 从数组中删除匹配元素的第一个实例

假设我有数组[1,2,3,1,2,3]并且我想从给出[1,3,1,2,3]的数组。什么是最简单的方法? 最佳答案 li.delete_at(li.index(n)||li.length)li[li.length]超出范围,所以||li.length处理n不在列表中的情况。irb(main):001:0>li=[1,2,3,1,2,3]=>[1,2,3,1,2,3]irb(main):002:0>li.delete_at(li.index(2)||li.length)=>2irb(main):003:0>li.delete_at(li